#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int a = 40;
	int b = 20;
	scanf("%d %d", &a, &b);
	int c = a % b;
	while(c != 0 )
	{
		int tmp = 0;
			tmp = a;
			a = b;
			b = c;
			c = a % b;
	}
	printf("%d", b);
	return 0;
}